<?php 
	try{
		$dsn = 'mysql:host=localhost;dbname=cityweather;charset=utf8';
		$user = 'root';
		$psw = '123456';
		$pdo = new PDO($dsn,$user,$psw,array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
	}catch (PDOException $ex) {
		die('数据库连接失败'.$ex->getMessage());  
	}

	$datas = json_decode($_POST['datas']);
	$cityName = $_GET['cityName'];
	$cityid = $_GET['cityid'];

	foreach ($datas as $key => $value) {
		$date = $value->date;
		$fengli = $value->fengli;
		$fengxiang = $value->fengxiang;
		$hightemp = $value->hightemp;
		$lowtemp = $value->lowtemp;
		$type = $value->type;
		$week = $value->week;

		$results = $pdo->query("INSERT INTO `cityweathertable`(`cityName`, `cityId`, `date`, `fengli`, `fengxiang`, `hightemp`, `lowtemp`, `type`, `week`) VALUES ('{$cityName}','{$cityid}','{$date}','{$fengli}','{$fengxiang}','{$hightemp}','{$lowtemp}','{$type}','{$week}')");
	}

	$pdo=null;
	echo "数据已提交";
	// CREATE TABLE `cityweather`.`cityWeatherTable` ( `id` INT NOT NULL AUTO_INCREMENT , `date` VARCHAR(20) NOT NULL , `fengli` VARCHAR(20) NOT NULL , `fengxiang` VARCHAR(20) NOT NULL , `hightemp` VARCHAR(20) NOT NULL , `lowtemp` VARCHAR(20) NOT NULL , `type` VARCHAR(20) NOT NULL , `week` VARCHAR(20) NOT NULL , `associated` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB; 
	// ALTER TABLE `cityweathertable` ADD `cityName` VARCHAR(20) NOT NULL AFTER `id`; 

 ?>